<?php
//A FINIR (headers) ET TESTER
	class Mail{
		var $to;
		var $subject;
		var $message;
		var $from;
		var $fromAdress;
		var $replyTo;
		
		function Mail($destinataire,$sujet,$message,$expediteur="",$adresseExpediteur="",$adresseDeReponse=""){
			$this->to=$destinataire;
			$this->subject=$sujet;
			$this->message=$message;
			$this->from=$expediteur;
			$this->fromAdress=$adresseExpediteur;
			$this->replyTo = $adresseDeReponse;
		}
		
		function headers(){
			$headers = '';
			if(!empty($this->from) && preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/",$this->fromAdress)) $headers .= 'From: '.$this->from.''."\r\n"; 
			if(!empty($this->replyTo)) $headers .= 'Reply-To: '.$this->replyTo.'\r\n'; 
			$headers .='Content-Type: text/html; charset=iso-8859-1'."\r\n";
			$headers .='Content-Transfer-Encoding: 8bit'; 
			return $headers;
		}
		
		function check(){
			if(!preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/",$this->to)) return -1;
			if(empty($this->subject)) return -2;
			if(empty($this->message)) return -3;
			return 1;
		}
		
		function send(){
			$errno = $this->check();
			if($errno<0) return $errno;
			return (mail($this->to,$this->subject,$this->message,$this->headers()))?1:0;
		}
	}
?>